home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wcomm111.zip / WARPCOMM.DOC < prev   
Text File  |  1991-02-03  |  18KB  |  654 lines

  1.                     The Warp Communications Library
  2.  
  3.                               Version 1.11
  4.  
  5.                                 written
  6.  
  7.                                    by
  8.  
  9.                               Trevor Bell
  10.  
  11.                 Copyright (C) 1991, All Rights Reserved.
  12.  
  13.  
  14. WHAT IT IS:
  15.  
  16.         The Warp Communications Library is a full-featured modem/serial
  17. communications library.  It can be used to create BBS doors, protocols,
  18. terminal programs, or actual BBS programs.  Currently the library only
  19. supports Turbo C and Turbo C++ with libraries for each, however support
  20. for MSC is on the way and if you are a registered user with the source
  21. code then you could easily modify the source to work with any C
  22. compiler.  Warp Comm supports baud rates of up to 57,600.  Warp Comm
  23. currently supports up to 8 com ports open in simultaneous operation
  24. however, this could be increased to almost any value with the source code.
  25.  
  26.         Warp Comm is NOT PUBLIC DOMAIN, Warp Comm IS SHAREWARE.  A
  27. registration fee of $25 (of course I won't mind if you send more than
  28. $25) is required if you wish to use Warp Comm in any application to be
  29. distributed to the general public.  Registration will get you the full
  30. source code for both the Turbo C and Turbo C++ libraries and library files
  31. for each of 5 memory models (small, medium, compact, large, huge).
  32. Without registration you will be limited to compiling programs in the small
  33. memory model and this will substantially limit programs.  By registering
  34. this program you will be contributing to the release of future versions
  35. of Warp Comm and future programs that I will be creating.  Your
  36. registration will be greatly appreciated.  See the file ORDER.FRM for
  37. details on registering.
  38.  
  39. Registrations may be sent to:
  40.  
  41.         Trevor Bell
  42.         P.O. Box 4173
  43.         Redondo Beach, CA  90278
  44.  
  45. I can be contacted on THE SOURCE BBS at 213-371-3737.
  46. I can also be reached at fidonet node 1:102/134.
  47.  
  48.  
  49. Two zip files are provided, one for Turbo C and Turbo C++ in standard
  50. C mode and one for Turbo C++ only in C++ mode.  They are:
  51.  
  52. TC.ZIP  (For C only)
  53. TCP.ZIP (For C++ only)
  54.  
  55.  
  56.  
  57. HOW TO USE IT:
  58.  
  59. --------------------------------------------------------------------------------
  60.  
  61.                For Turbo C++ and Turbo C users in Standard C mode
  62.  
  63. --------------------------------------------------------------------------------
  64.  
  65. The file WARPCOMM.H must be included in any program wishing to use the
  66. Warp Comm library in TC, and the library file WCOMMS.LIB must be linked with
  67. the program.
  68.  
  69.  
  70. Opening the Com Port:
  71. ---------------------
  72.  
  73. void com_open (unsigned int port, unsigned int baud_rate,
  74.         unsigned int interrupt_request,
  75.         unsigned int base_address, unsigned int receive_buffer_size,
  76.         unsigned int transmit_buffer_size);
  77.  
  78. port - which com port to open
  79.  
  80. baud_rate - the baud rate to open the com port at
  81.  
  82. interrupt request - which IRQ to open the comport at, usual values are
  83.         as follows:
  84.  
  85.         COM port 1: IRQ 4
  86.         COM port 2: IRQ 3
  87.  
  88.         all other COM ports are non-standard and would be machine
  89.         dependent.
  90.  
  91. base_address - which base address to use, common values are as follow:
  92.  
  93.         COM port 1: 0x3f8 (Hex)
  94.         COM port 2: 0x2f8 (Hex)
  95.  
  96. receive buffer size - this can vary with modem speed and the application
  97.         being used however, 2000 characters is usually a good place to start.
  98.  
  99. transmit buffer size - this can vary with modem speed and the application
  100.         being used however, 2000 characters is usually a good place to start.
  101.  
  102. Thus opening COM 1 at 2400 baud would work like this:
  103.  
  104.         com_open(2400, 4, 0x3F8, 2000, 2000);
  105.  
  106.  
  107. Outputting to the Com Port:
  108. ---------------------------
  109.  
  110. void com_out_char(unsigned int port, char value);
  111.  
  112. Outputting to the comport in TC is accomplished like this:
  113.  
  114. char value = 13;
  115. com_out_char(0, value);
  116.  
  117.  
  118. Inputting from the Com Port:
  119. ----------------------------
  120.  
  121. void com_get_char(unsigned int port);
  122.  
  123. Inputting from the comport in TC is accomplished like this:
  124.  
  125. char value;
  126. value=com_get_char(0);
  127.  
  128.  
  129. Checking for a character waiting to be read:
  130. --------------------------------------------
  131.  
  132. void char_waiting(unsigned int port);
  133.  
  134. Often it is necessary to know if there is a character waiting in the com
  135. port receive buffer, this can be checked with the char_waiting function
  136. which returns a 1 if there is a character or characters waiting, and a 0
  137. if the com port buffer is empty.  It is used like this:
  138.  
  139. char value;
  140.  
  141. if( char_waiting(0)) {
  142.     value=com_get_char(0);
  143. }
  144.  
  145.  
  146. Closing the Com Port:
  147. ---------------------
  148.  
  149. void com_close(unsigned int port);
  150.  
  151. Closing out the com port is a simple task, it will disable com port
  152. interrupt routine, and free the memory allocated by the transmit and receive
  153. buffers.  It is used like this:
  154.  
  155. com_close(0);
  156.  
  157.  
  158. Sending a string to the Com Port:
  159. ---------------------------------
  160.  
  161. void com_out_char_str(unsigned int port, char *string);
  162. void send_modem_string(unsigned int port, char *string);
  163.  
  164. A null terminated string can be sent to the com port like this:
  165.  
  166. char *string="This is a null-terminated string.";
  167. com_out_char_str(0, string);
  168.  
  169. an alternate method of sending strings to the modem can also be used,
  170. like this:
  171.  
  172. send_modem_string(0, "ATZ|");
  173.  
  174. where the | command represents a carriage return.
  175.  
  176.  
  177.  
  178. Sending a buffer to the Com Port:
  179. ---------------------------------
  180.  
  181. void com_out_buf(unsigned int port, unsigned char *buffer, unsigned int length);
  182.  
  183. A buffer of a specified size can be sent to the com port like this:
  184.  
  185. unsigned char *buffer;
  186. unsigned int length=10;
  187. com_out_buf(0, buffer,length);
  188.  
  189.  
  190. Receiving a buffer from the Com Port:
  191. -------------------------------------
  192.  
  193. void com_get_buf(unsigned int port, unsigned char *buffer, unsigned int length);
  194.  
  195. A buffer of a specified size can be received from the com port like this:
  196.  
  197. unsigned char *buffer;
  198. unsigned int length=10;
  199. com_get_buf(0, buffer,length);
  200.  
  201.  
  202. Setting the DTR pin of the modem:
  203. ---------------------------------
  204.  
  205. void set_dtr(unsigned int port, unsigned int value);
  206.  
  207. The DTR pin of the modem can be changed like this:
  208.  
  209. set_dtr(0, 1);
  210.  
  211. A value of 1 will hold the DTR high, a value of 0 will hold it low
  212. causing most modems to hangup.
  213.  
  214.  
  215. Setting the RTS pin of the modem:
  216. ---------------------------------
  217.  
  218. void set_rts(unsigned int port, unsigned int value);
  219.  
  220. The RTS pin of the modem can be changed like this:
  221.  
  222. set_rts(0, 1);
  223.  
  224. A value of 1 will hold the RTS high allowing some modems to use hardware
  225. flow control (consult your modem manual on this), a value of 0 will
  226. hold it low.
  227.  
  228.  
  229. Clearing the transmit or receive buffers:
  230. -----------------------------------------
  231.  
  232. void clear_xmit_buffer(unsigned int port);
  233.  
  234. Clearing the transmit buffer will clear any characters waiting to be
  235. sent to the com port and is accomplished like this:
  236.  
  237. clear_xmit_buffer(0);
  238.  
  239. Clearing the receive buffer will clear any characters waiting to be
  240. received the com port and is accomplished like this:
  241.  
  242. clear_receive_buffer(0);
  243.  
  244.  
  245. Changing the baud rate:
  246. -----------------------
  247.  
  248. void set_baudrate(unsigned int port, unsigned int baud_rate);
  249.  
  250. Changing the baud rate on the modem is accomplished like this:
  251.  
  252. set_baudrate(0, 2400);
  253.  
  254.  
  255. Detecting a Carrier:
  256. --------------------
  257.  
  258. The carrier detect pin of the modem can be checked by examining the
  259. integer variable CD.  If CD is 1 then a carrier is present, if CD is 0
  260. then no carrier is present.  It can be used like this:
  261.  
  262. if(remote[0].CD==1) {
  263.     puts("A carrier is detected.");
  264. }
  265.  
  266. Reading the interrupt enable register:
  267. --------------------------------------
  268.  
  269. unsigned char read_ier(unsigned int port);
  270.  
  271. The interrupt enable register can be read like this:
  272.  
  273. unsigned char value;
  274. value=read_ier(0);
  275.  
  276.  
  277. Reading the line status register:
  278. --------------------------------------
  279.  
  280. unsigned char read_lsr(unsigned int port);
  281.  
  282. The line status register can be read like this:
  283.  
  284. unsigned char value;
  285. value=read_lsr(0);
  286.  
  287.  
  288. Reading the modem status register:
  289. --------------------------------------
  290.  
  291. unsigned char read_msr(unsigned int port);
  292.  
  293. The modem status register can be read like this:
  294.  
  295. unsigned char value;
  296. value=read_msr(0);
  297.  
  298.  
  299. Reading the line control register:
  300. --------------------------------------
  301.  
  302. unsigned char read_lcr(unsigned int port);
  303.  
  304. The line control register can be read like this:
  305.  
  306. unsigned char value;
  307. value=read_lcr(0);
  308.  
  309.  
  310. Reading the modem control register:
  311. --------------------------------------
  312.  
  313. unsigned char read_mcr(unsigned int port);
  314.  
  315. The modem control register can be read like this:
  316.  
  317. unsigned char value;
  318. value=read_mcr(0);
  319.  
  320.  
  321.  
  322. --------------------------------------------------------------------------------
  323.  
  324.                       Turbo C++ users in C++ mode
  325.  
  326. --------------------------------------------------------------------------------
  327.  
  328. The file WARPCOMM.HPP must be included in any program wishing to use the
  329. Warp Comm library in TC++, and the library file WCOMMS.LIB must be linked with
  330. the program.  In the Turbo C++ versions of the library all the commands
  331. and most of the data structures are contained within the COM_port class,
  332. and thus must be accessed through the variable remote which is defined
  333. like this:
  334.  
  335. COM_port remote[8];
  336.  
  337. Opening the Com Port:
  338. ---------------------
  339.  
  340. void open (unsigned int port, unsigned int baud_rate,
  341.         unsigned int interrupt_request, unsigned int base_address,
  342.         unsigned int receive_buffer_size, unsigned int transmit_buffer_size);
  343.  
  344. port - this is the com port you are opening, this number should match
  345.        the array element of remote you are using
  346.  
  347. baud_rate - the baud rate to open the com port at
  348.  
  349. interrupt request - which IRQ to open the comport at, usual values are
  350.         as follows:
  351.  
  352.         COM port 1: IRQ 4
  353.         COM port 2: IRQ 3
  354.  
  355.         all other COM ports are non-standard and would be machine
  356.         dependent.
  357.  
  358. base_address - which base address to use, common values are as follow:
  359.  
  360.         COM port 1: 0x3f8 (Hex)
  361.         COM port 2: 0x2f8 (Hex)
  362.  
  363. receive buffer size - this can vary with modem speed and the application
  364.         being used however, 2000 characters is usually a good place to start.
  365.  
  366. transmit buffer size - this can vary with modem speed and the application
  367.         being used however, 2000 characters is usually a good place to start.
  368.  
  369. Thus opening COM 1 at 2400 baud with an IRQ of 4 and with 2000 byte receive
  370. and transmit buffers would work like this:
  371.  
  372.         remote[0].open(0, 2400, 4, 0x3F8, 2000, 2000);
  373.  
  374.  
  375. Outputting to the Com Port:
  376. ---------------------------
  377.  
  378. Outputting to the comport in TC++ is identical to file stream output in C++,
  379. you simply use the overloaded bitshift operator with the variable to
  380. output to the port, like this:
  381.  
  382. char value = 13;
  383. remote[0] << value;
  384.  
  385.  
  386. Inputting from the Com Port:
  387. ----------------------------
  388.  
  389. Inputting from the comport in TC++ is identical to file stream input in C++,
  390. you simply use the overloaded bitshift operator with the variable to
  391. input from the port, like this:
  392.  
  393. char value;
  394. remote[0] >> value;
  395.  
  396.  
  397. Checking for a character waiting to be read:
  398. --------------------------------------------
  399.  
  400. Often it is necessary to know if there is a character waiting in the com
  401. port receive buffer, this can be checked with the char_waiting function
  402. which returns a 1 if there is a character or characters waiting, and a 0
  403. if the com port buffer is empty.  It is used like this:
  404.  
  405. char value;
  406.  
  407. if( remote[0].char_waiting()) {
  408.     remote[0] >> value;
  409. }
  410.  
  411.  
  412. Closing the Com Port:
  413. ---------------------
  414.  
  415. void close(void);
  416.  
  417. Closing out the com port is a simple task, it will disable com port
  418. interrupt routine, and free the memory allocated by the transmit and receive
  419. buffers.  It is used like this:
  420.  
  421. remote[0].close();
  422.  
  423.  
  424. Sending a string to the Com Port:
  425. ---------------------------------
  426.  
  427. void send_modem_string(char *s);
  428.  
  429. A null terminated string can be sent to the com port like this:
  430.  
  431. char *string="This is a null-terminated string.";
  432. remote[0] << string;
  433.  
  434. an alternate method of sending strings to the modem can also be used,
  435. like this:
  436.  
  437. remote[0].send_modem_string("ATZ|");
  438.  
  439. where the | command represents a carriage return.
  440.  
  441.  
  442. Sending a buffer to the Com Port:
  443. ---------------------------------
  444.  
  445. void out_buf(unsigned char *buffer, unsigned int length);
  446.  
  447. A buffer of a specified size can be sent to the com port like this:
  448.  
  449. unsigned char *buffer;
  450. unsigned int length=10;
  451. remote[0].out_buf(buffer,length);
  452.  
  453.  
  454. Receiving a buffer from the Com Port:
  455. -------------------------------------
  456.  
  457. void get_buf(unsigned char *buffer, unsigned int length);
  458.  
  459. A buffer of a specified size can be received from the com port like this:
  460.  
  461. unsigned char *buffer;
  462. unsigned int length=10;
  463. remote[0].get_buf(buffer,length);
  464.  
  465.  
  466. Setting the DTR pin of the modem:
  467. ---------------------------------
  468.  
  469. void set_dtr(unsigned int value);
  470.  
  471. The DTR pin of the modem can be changed like this:
  472.  
  473. remote[0].set_dtr(1);
  474.  
  475. A value of 1 will hold the DTR high, a value of 0 will hold it low
  476. causing most modems to hangup.
  477.  
  478.  
  479. Setting the RTS pin of the modem:
  480. ---------------------------------
  481.  
  482. void set_rtr(unsigned int value);
  483.  
  484. The RTS pin of the modem can be changed like this:
  485.  
  486. remote[0].set_rts(1);
  487.  
  488. A value of 1 will hold the RTS high allowing some modems to use hardware
  489. flow control (consult your modem manual on this), a value of 0 will
  490. hold it low.
  491.  
  492.  
  493. Clearing the transmit or receive buffers:
  494. -----------------------------------------
  495.  
  496. void clear_xmit_buffer(void);
  497. void clear_receive_buffer(void);
  498.  
  499. Clearing the transmit buffer will clear any characters waiting to be
  500. sent to the com port and is accomplished like this:
  501.  
  502. remote[0].clear_xmit_buffer();
  503.  
  504. Clearing the receive buffer will clear any characters waiting to be
  505. received the com port and is accomplished like this:
  506.  
  507. remote[0].clear_receive_buffer();
  508.  
  509.  
  510. Changing the baud rate:
  511. -----------------------
  512.  
  513. void set_baudrate(unsigned int baud_rate);
  514.  
  515. Changing the baud rate on the modem is accomplished like this:
  516.  
  517. remote[0].set_baudrate(2400);
  518.  
  519.  
  520. Detecting a Carrier:
  521. --------------------
  522.  
  523. The carrier detect pin of the modem can be checked by examining the
  524. integer variable CD.  If CD is 1 then a carrier is present, if CD is 0
  525. then no carrier is present.  It can be used like this:
  526.  
  527. if(remote[0].CD==1) {
  528.     puts("A carrier is detected.");
  529. }
  530.  
  531.  
  532. Reading the interrupt enable register:
  533. --------------------------------------
  534.  
  535. unsigned char read_ier(void);
  536.  
  537. The interrupt enable register can be read like this:
  538.  
  539. unsigned char value;
  540. value=remote[0].read_ier();
  541.  
  542.  
  543. Reading the line status register:
  544. --------------------------------------
  545.  
  546. unsigned char read_lsr(void);
  547.  
  548. The line status register can be read like this:
  549.  
  550. unsigned char value;
  551. value=remote[0].read_lsr();
  552.  
  553.  
  554. Reading the modem status register:
  555. --------------------------------------
  556.  
  557. unsigned char read_msr(void);
  558.  
  559. The modem status register can be read like this:
  560.  
  561. unsigned char value;
  562. value=remote[0].read_msr();
  563.  
  564.  
  565. Reading the line control register:
  566. --------------------------------------
  567.  
  568. unsigned char read_lcr(void);
  569.  
  570. The line control register can be read like this:
  571.  
  572. unsigned char value;
  573. value=remote[0].read_lcr();
  574.  
  575.  
  576. Reading the modem control register:
  577. --------------------------------------
  578.  
  579. unsigned char read_mcr(void);
  580.  
  581. The modem control register can be read like this:
  582.  
  583. unsigned char value;
  584. value=remote[0].read_mcr();
  585.  
  586.  
  587.  
  588. --------------------------------------------------------------------------------
  589.  
  590.                              CODE EXAMPLES
  591.  
  592. --------------------------------------------------------------------------------
  593.  
  594.  
  595. A very simple terminal program is provided with Warp Comm to demonstrate
  596. it's capabilities very minimally.  Feel free to modify it to your
  597. heart's desire, keep in mind however that without registration your
  598. program will need to remain within the small memory model.
  599.  
  600. The source code for this program is provided in the file TERM.C or
  601. TERM.CPP for TC and TC++ respectively.
  602.  
  603.  
  604.  
  605. --------------------------------------------------------------------------------
  606.  
  607.                                 SUPPORT
  608.  
  609. --------------------------------------------------------------------------------
  610.  
  611.  
  612. Support can be obtained through mail sent to my P.O. Box or by calling the
  613. following BBS:
  614.  
  615.         Name:           The Source
  616.         SysOp:          Chip North
  617.         BBS Software:   Wildcat
  618.         Phone #:        213-371-3737
  619.  
  620. I can also be reached at fidonet node 1:102/134.
  621.  
  622. --------------------------------------------------------------------------------
  623.  
  624.                             VERSION HISTORY
  625.  
  626. --------------------------------------------------------------------------------
  627.  
  628.  
  629. Version 1.00:
  630.         not released to the public
  631.  
  632. Version 1.01:
  633.         My first release!
  634.  
  635. Version 1.02:
  636.         Fixed null pointer assignment.
  637.  
  638. Version 1.03:
  639.         Fixed some other minor bugs.
  640.  
  641. Version 1.04:
  642.         Sped up the interrupt service routine a bit.
  643.  
  644. Version 1.10:
  645.         Multi-Line Support added!!!
  646.         Added functions to read all of the important UART ports.
  647.         Rewrote almost all functions to add multi-com port support and
  648.         better optimization.
  649.  
  650. Version 1.11:
  651.         Maintenance release - included the outstr.obj file to the library
  652.         which should have been there since the beginning.
  653.  
  654.